package com.itheima.day11.myOtherio.test2;

import java.io.*;

/*
    需求：创建多个Javabean类对象写到文件中，再次读取到内存中。
 */
public class StudentDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 创建学生对象
        Student stu1 = new Student("itheima001","张三");
        Student stu2 = new Student("itheima002","李四");
        Student stu3 = new Student("itheima003","王五");

        // 创建对象序列化流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("myCode\\src\\com\\itheima\\day11\\h.txt"));
        // 完成学生对象的序列化操作
        oos.writeObject(stu1);
        oos.writeObject(stu2);
        oos.writeObject(stu3);
        oos.close();

        // 创建对象反序列化流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("myCode\\src\\com\\itheima\\day11\\h.txt"));
        Object o1 = ois.readObject();
        Object o2 = ois.readObject();
        Object o3 = ois.readObject();
        System.out.println(o1);
        System.out.println(o2);
        System.out.println(o3);
        ois.close();

    }
}
